package k8s

/*
HTTPChaos

无法从 故障ID 生成 默认故障
通过代理实现故障。不需要通过 Chaos Mesh 注入
*/

//import (
//	"context"
//
//	"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
//	"k8s.io/apimachinery/pkg/apis/meta/v1"
//
//	"github.com/chaos-mesh/chaos-mesh/pkg/proxy/slog"
//	"github.com/chaos-mesh/chaos-mesh/pkg/proxy/testtask"
//	"github.com/chaos-mesh/chaos-mesh/pkg/proxy/util"
//)
//
//func injectHTTPChaos(kind v1alpha1.PodHttpChaosTarget, name string,
//	labels map[string]string, port int, path string, abort bool) {
//	var podHttpChaosActions v1alpha1.PodHttpChaosActions
//	if abort {
//		podHttpChaosActions.Abort = util.GetPointer(true)
//	} else {
//		podHttpChaosActions.Delay = enoughDuration
//	}
//	newHTTPChaos := v1alpha1.HTTPChaos{
//		ObjectMeta: v1.ObjectMeta{
//			Name: name,
//		},
//		Spec: v1alpha1.HTTPChaosSpec{
//			PodSelector: v1alpha1.PodSelector{
//				Selector: v1alpha1.PodSelectorSpec{
//					GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
//						// 注入目标所在命名空间
//						Namespaces:     []string{testtask.TestNamespaceName},
//						LabelSelectors: labels,
//					},
//				},
//				Mode: "all",
//			},
//			Target:              kind,
//			PodHttpChaosActions: podHttpChaosActions,
//			Port:                int32(port),
//			Path:                &path,
//			Duration:            util.GetPointer("10m"),
//		},
//	}
//	for {
//		err := chaosMesh.Post().
//			Namespace(chaosMeshObjectNamespace).Resource(ResourceHTTP).
//			Body(&newHTTPChaos).Do(context.TODO()).Into(&newHTTPChaos)
//		if err != nil {
//			slog.Slog.Warnf("故障 %s labels %v 注入错误 %s 将重试", name, labels, err.Error())
//		} else {
//			break
//		}
//	}
//}
//
//func InjectHTTPRequestAbort(name string, labels map[string]string, port int, path string) {
//	injectHTTPChaos(v1alpha1.PodHttpRequest, name, labels, port, path, true)
//}
//
//func InjectHTTPRequestDelay(name string, labels map[string]string, port int, path string) {
//	injectHTTPChaos(v1alpha1.PodHttpRequest, name, labels, port, path, false)
//}
//
//func InjectHTTPResponseAbort(name string, labels map[string]string, port int, path string) {
//	injectHTTPChaos(v1alpha1.PodHttpResponse, name, labels, port, path, true)
//}
//
//func InjectHTTPResponseDelay(name string, labels map[string]string, port int, path string) {
//	injectHTTPChaos(v1alpha1.PodHttpResponse, name, labels, port, path, false)
//}
